
const Cookies = require('js-cookie') // element-ui

const getDefaultState = () => {
  return {
    scrollTop: 0,
    sidebar: {
      opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : true,
      withoutAnimation: false
    },
    device: 'desktop',
    appMainWidth: '',
    appMainWidthView: '',
    userInfo: '',
    currentRouter: {},
    pageName: '',
    isOpenSetting: '', // 是否展示设置栏
    router: {},
    bsiCountryList: [], // 国家列表
    customerList: [], // 客户列表
    userStation: {}// 用户站点代码
  }
}
const state = getDefaultState()


const mutations = {
  TOGGLE_SIDEBAR: state => {
    state.sidebar.opened = !state.sidebar.opened
    state.sidebar.withoutAnimation = false
    if (state.sidebar.opened) {
      Cookies.set('sidebarStatus', 1)
    } else {
      Cookies.set('sidebarStatus', 0)
    }
  },
  CLOSE_SIDEBAR: (state, withoutAnimation) => {
    Cookies.set('sidebarStatus', 0)
    state.sidebar.opened = false
    state.sidebar.withoutAnimation = withoutAnimation
  },
  TOGGLE_DEVICE: (state, device) => {
    state.device = device
  },
  SET_SCROLLTOP: (state, scrollTop) => {
    state.scrollTop = scrollTop
  },
  SET_USET_INFO: (state, payload) => {
    state.userInfo = payload
  },
  SET_CURRRNT_ROUTER: (state, payload) => {
    state.currentRouter = payload
  },
  SET_PAGENAME: (state, payload) => {
    state.pageName = payload
  },
  SET_ROUTER: (state, payload) => {
    state.router = payload
  },
  SET_BSICOUNTRYLIST: (state, payload) => {
    state.bsiCountryList = payload
  },
  SET_CUSTOMERLIST: (state, payload) => {
    state.customerList = payload
  },
  SET_USERSTATION: (state, payload) => {
    state.userStation = payload
  },
  SET_APPMAINWIDTH: (state, payload) => {
    state.appMainWidth = payload
  },
  SET_APPMAINWIDTHVIEW: (state, payload) => {
    state.appMainWidthView = payload
  }

}

const actions = {

  setScrollTop: ({ commit }, scrollTop) => {
    commit('SET_SCROLLTOP', scrollTop)
  },
  toggleSideBar: ({ commit }) => {
    commit('TOGGLE_SIDEBAR')
  },
  closeSideBar: ({ commit }, { withoutAnimation }) => {
    commit('CLOSE_SIDEBAR', withoutAnimation)
  },
  toggleDevice: ({ commit }, device) => {
    commit('TOGGLE_DEVICE', device)
  },
  setUserInfo: ({ commit }, payload) => {
    commit('SET_USET_INFO', payload)
  },
  setCurrentRouter: ({ commit }, payload) => {
    commit('SET_CURRRNT_ROUTER', payload)
  },
  setPageName: ({ commit }, payload) => {
    commit('SET_PAGENAME', payload)
  },
  setRouter: ({ commit }, payload) => {
    commit('SET_ROUTER', payload)
  },
  setAppMainWidth: ({ commit }, payload) => {
    commit('SET_APPMAINWIDTH', payload)
  },
  setAppMainWidthView: ({ commit }, payload) => {
    commit('SET_APPMAINWIDTHVIEW', payload)
  }

}


export default {
  namespaced: true,
  state,
  mutations,
  actions
}
